import { readFile, writeFile } from './FileAction'
import { ipcMain } from 'electron'
const initIpAction = () => {
  ipcMain.on('render-msg', async (event, arg, data) => {
    let con = await getFileMessage(arg, JSON.stringify(data))
    event.sender.send('person-list', con)
  })
}

const getFileMessage = async (action: string, args: any) => {
  let con
  switch (action) {
    case 'getList':
      con = await readFile('./public/Equips.json')
      break
    case 'writeList':
      con = await writeFile('./public/Equips.json', args)
      break
    case 'getTipsList':
      con = await readFile('./public/TipsList.json')
      break
    default:
      break
  }
  return {
    action: action,
    data: con
  }
}
export { initIpAction }
